<template>
  <div class="menu">
    <el-aside width="200px">
      <el-menu
        :default-active="activePath"
        class="el-menu-vertical-demo"
        router
        @open="handleOpen"
        @close="handleClose"
        background-color="#1e74ba"
        text-color="#fff"
        active-text-color="#ffd04b"
        unique-opened
      >
        <template v-for="(item, index) in optionList">
          <el-submenu :index="index + ''" :key="index" v-if="!item.hidden">
            <template slot="title">
              <i :class="item.iconClass"></i>
              <span>{{ item.name }}</span>
            </template>
            <el-menu-item-group>
              <el-menu-item
                :index="child.path"
                v-for="(child, index) in item.children"
                :key="index"
              >
                <i :class="child.iconClass"></i>
                <span>{{ child.name }}</span>
              </el-menu-item>
            </el-menu-item-group>
          </el-submenu>
        </template>
      </el-menu>
    </el-aside>
  </div>
</template>

<script>
export default {
  data() {
    return {
      optionList: [],
      activePath: "/home/studentList",
    };
  },
  methods: {
    handleOpen(key, keyPath) {
      // console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      // console.log(key, keyPath);
    },
  },
  created() {
    this.activePath = this.$route.path; // 当前的路由路径
    this.optionList = this.$router.options.routes; // 拿到所有路由的信息
    // console.log(this.$router.options.routes);
  },
};
</script>

<style lang="scss" scoped>
.menu {
  .el-aside {
    height: 100%;

    .el-menu {
      height: 100%;
    }

    .el-submenu .el-menu-item {
      min-width: 0;
    }
  }
  .fa {
    margin-right: 10px;
    color: #fff;
  }
}
</style>
